package com.tcm.controller.front;

import com.tcm.entity.resp.R;
import com.tcm.service.ScoreService;
import com.tcm.utils.AccessTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 学生积分控制器
 * @author Guqier
 * @version 1.0
 * @date 2023/8/24 16:44
 */
@RestController
@RequestMapping("/stu/score")
public class StuScoreController {

    @Autowired
    private ScoreService scoreService;

    /**
     * 获取全部学生积分排行榜
     * @param request 请求对象
     * @return 全部学生积分排行榜
     */
    @RequestMapping(value = "/student", method = RequestMethod.GET)
    public R getAllStudentRank(HttpServletRequest request){
        return R.success(scoreService.getAllStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取班级学生积分排行榜
     * @param request 请求对象
     * @return 班级学生积分排行榜
     */
    @RequestMapping(value = "/student/clazz", method = RequestMethod.GET)
    public R getClazzStudentRank(HttpServletRequest request){
        return R.success(scoreService.getClazzStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取专业学生积分排行榜
     * @param request 请求对象
     * @return 专业学生积分排行榜
     */
    @RequestMapping(value = "/student/major", method = RequestMethod.GET)
    public R getMajorStudentRank(HttpServletRequest request){
        return R.success(scoreService.getMajorStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取学院学生积分排行榜
     * @param request 请求对象
     * @return 学院学生积分排行榜
     */
    @RequestMapping(value = "/student/college", method = RequestMethod.GET)
    public R getCollegeStudentRank(HttpServletRequest request){
        return R.success(scoreService.getCollegeStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取所有社会化学员积分排行榜
     * @param request 请求对象
     * @return 所有社会化学员积分排行榜
     */
    @RequestMapping(value = "/social", method = RequestMethod.GET)
    public R getAllSocialStudentRank(HttpServletRequest request){
        return R.success(scoreService.getAllSocialStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取班级社会化学员积分排行榜
     * @param request 请求对象
     * @return 班级社会化学员积分排行榜
     */
    @RequestMapping(value = "/social/clazz", method = RequestMethod.GET)
    public R getClazzSocialStudentRank(HttpServletRequest request){
        return R.success(scoreService.getClazzSocialStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取项目社会化学员积分排行榜
     * @param request 请求对象
     * @return 项目社会化学员积分排行榜
     */
    @RequestMapping(value = "/social/project", method = RequestMethod.GET)
    public R getProjectSocialStudentRank(HttpServletRequest request){
        return R.success(scoreService.getProjectSocialStudentRank(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 分页获取积分记录
     * @param page 页码
     * @param pageSize 每页数量
     * @param request 请求对象
     * @return 积分记录
     */
    @RequestMapping(value = "/record", method = RequestMethod.GET)
    public R getScoreRecord(@RequestParam Integer page, @RequestParam Integer pageSize, HttpServletRequest request){
        return R.success(scoreService.getScoreRecordByPage(page, pageSize, AccessTokenUtil.getUserAccount(request)));
    }

}
